package com.openvas.controller;

import java.util.List;
////    import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;
import com.openvas.commons.common.core.page.TableDataInfo;
import com.openvas.commons.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.openvas.domain.TableConfig;
import com.openvas.service.ITableConfigService;

/**
 * 配置Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Api(tags = "任务配置")
@Controller
@RequestMapping("/api/config")
public class TableConfigController extends BaseController
{
    private String prefix = "system/config";

    @Autowired
    private ITableConfigService tableConfigService;

//   // //  @RequiresPermissions("system:config:view")
    @ApiOperation("123")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询配置列表
     */
//   // //  @RequiresPermissions("system:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableConfig tableConfig)
    {
        startPage();
        List<TableConfig> list = tableConfigService.selectTableConfigList(tableConfig);
        return getDataTable(list);
    }

    /**
     * 导出配置列表
     */
//   // //  @RequiresPermissions("system:config:export")
    @Log(title = "配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableConfig tableConfig)
    {
        List<TableConfig> list = tableConfigService.selectTableConfigList(tableConfig);
//        ExcelUtil<TableConfig> util = new ExcelUtil<TableConfig>(TableConfig.class);
//        return util.exportExcel(list, "配置数据");
        return null;
    }

    /**
     * 新增配置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存配置
     */
//   // //  @RequiresPermissions("system:config:add")
    @Log(title = "配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableConfig tableConfig)
    {
        return toAjax(tableConfigService.insertTableConfig(tableConfig));
    }

    /**
     * 修改配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TableConfig tableConfig = tableConfigService.selectTableConfigById(id);
        mmap.put("tableConfig", tableConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存配置
     */
//   // //  @RequiresPermissions("system:config:edit")
    @Log(title = "配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableConfig tableConfig)
    {
        return toAjax(tableConfigService.updateTableConfig(tableConfig));
    }

    /**
     * 删除配置
     */
//   // //  @RequiresPermissions("system:config:remove")
    @Log(title = "配置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableConfigService.deleteTableConfigByIds(ids));
    }
}
